<template>
  <div class="transaction-service-list bg-c-fff right-height mb70">
    <p class="bread rel">
      <a href="#/index/news-content" class="font-s-16">内容管理-新闻资讯</a> >
      <a href="javascript:void(0);" class="font-s-14">列表</a>
      <a href="#/addnews">
        <button class="xl-btn-css blue-button abs">新增新闻</button>
      </a>
    </p>
    <div class="content">
      <div class="seach">
        <input type="text" name="" class="input-css" v-model="keyword">
        <button class="xl-btn-css blue-button vb" @click="getData(1)">搜索</button>
      </div>
      <table width="94%" class="auto">
        <tr>
          <th>新闻标题</th>
          <th>新闻摘要</th>
          <th>新闻预览图片</th>
          <th>提交时间</th>
          <th>操作</th>
        </tr>
        <tr v-for='item in newList'>
          <td>{{item.title}}</td>
          <td>{{item.roundup}}</td>
          <td><img class="content-img" :src="item.image"></td>
          <td>{{item.createTime}}</td>
          <td>
            <button class="blue-button small-btn-css" @click="onEdit(item.id)">编辑</button>
            <button class="blue-button small-btn-css" @click="onDelete(item.id)">删除</button>
          </td>
        </tr>
      </table>
      <div class="noData" v-show="this.newList.length===0">没有数据。。。</div>
      <div class="fix foot-box">
        <pagination :index="pageIndex" :total="pageTotal" v-show="this.newList.length!=0" @pagechange="onPageChange"></pagination>
      </div>
    </div>
  </div>
</template>
<script type="text/javascript">
// import axios from "axios"
import Pagination from '../components/Pagination'
export default {
  components: {
    Pagination
  },
  data() {
    return {
      pageIndex: 1,
      pageTotal: 0,
      newList: [],
      title: '',
      newName: '',
      newImg: '',
      time: '',
      keyword: '',
      isDeleteing: false
    }
  },
  mounted() {
    this.getData(1)
  },
  methods: {
    onEdit(id) {
      this.$router.push('/addnews?id=' + id)
    },
    onDelete(id) {
      if (this.isDeleteing) {
        return
      }
      this.isDeleteing = true
      this.$http.delete('/sysContent/del/' + id).then(data => {
        this.isDeleteing = false
        if (data.data.httpCode === 200) {
          this.newList.forEach((item, index) => {
            if (item.id === id) {
              this.newList.splice(index, 1)
            }
          })
          this.$toasted.show('删除成功')
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        this.isDeleteing = false
        console.log(err)
      })
    },
    getData(n) {
      var parms = {
        page: n,
        rows: 10,
        type: 1,
        title: this.keyword
      }
      this.$http.get('/sysContent/list', {
        params: parms
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.pageIndex = n
          this.pageTotal = Math.ceil(data.data.total / 10)
          this.newList = data.data.rows
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
      })
    },
    onPageChange(n) {
      this.getData(n)
    }
  }
}

</script>
<style type="text/css" scoped>
.bread {
  padding-left: 20px;
  border-bottom: 1px solid #ddd;
}

.bread a {
  line-height: 45px;
}

.bread button {
  right: 10px;
  top: 8px;
}

.content .seach input,
.content .seach button {
  height: 35px;
  line-height: 35px;
}

.content .seach {
  padding: 20px 30px;
}

.content .seach button {
  margin-left: -5px;
}

.foot-box {
  padding-top: 35px;
}

</style>
